package com.desire.homework;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @author LittleDesire
 * @description
 * @date 2022-02-09 周三 21:14
 * @since 17
 */
public class _52_反射打印出String类的所有方法名 {
    public static void main(String[] args) {
        //打印出java.lang.String类的所有方法名称
        Class<String> stringClass = String.class;
        Method[] methods = stringClass.getDeclaredMethods();
        StringBuilder builder = new StringBuilder();
        int rows = 0;
        for (Method method : methods) {
            Parameter[] parameters = method.getParameters();
            for (Parameter parameter : parameters) {
                builder.append(parameter.getType()).append(" ").append(parameter.getName()).append(",");
            }
            if (builder.length() > 0) {
                builder.deleteCharAt(builder.length() - 1);
                System.out.printf("%d、String.%s(%s);%n", ++rows, method.getName(), builder);
                builder.delete(0, builder.length());
            }
        }
    }
}
